import Vue from 'vue'
import Vuex from 'vuex'
import http from '@/util/httpAxios'
Vue.use(Vuex)

export default new Vuex.Store({
  //state公共状态
  state: {
    cityId: '310100',
    cityName: '上海',
    CinemasData: []
  },
  actions: {
    getCinemasData(store) {
      return http({
        url: `gateway?cityId=${store.state.cityId}&ticketFlag=1&k=362207`,
        headers: {
          'X-Client-Info':
            '{"a":"3000","ch":"1002","v":"5.2.1","e":"16737777312402682014793729","bc":"110100"}',
          'X-Host': 'mall.film-ticket.cinema.list'
        }
      }).then((res) => {
        console.log(res.data.data.cinemas)
        store.commit('changeCinemasData', res.data.data.cinemas)
      })
    }
  },
  mutations: {
    changeCityName(staye, cityName) {
      staye.cityName = cityName
    },
    changeCityId(staye, cityId) {
      staye.cityId = cityId
    },
    changeCinemasData(staye, CinemasData) {
      staye.CinemasData = CinemasData
    },
    clearCinema(state) {
      state.CinemasData = []
    }
  }
})
